package Room;

import javax.swing.JTextArea;
import Actions.Callback;

public class Room extends JTextArea{

	private static final long serialVersionUID = 1L;
	private String filename;
	private String filepath;
	private Callback modifiedCallback;
	
	private boolean isModified = false;
	
	public boolean caretSafe = false;
	
	public Room()
	{
		// doesn't do much...
		super();
	}
	// private setup function
	public void start(TypeWriter.TypeWriter parent)
	{

		// now set editor attributes
		TypeWriter.Options opts = parent.getOptions();
		
		setFont( opts.font );
		setLineWrap(true);
		setWrapStyleWord(true);
		
		setBackground(opts.background);
		setForeground(opts.foreground);
		setCaretColor(opts.foreground);
		
		
		filename = null;
		filepath = null;
	}
	
	// clear contents of editor
	public void clear()
	{
		caretSafe = true;
		setText("");
		caretSafe = false;
	}
	
	public String getFilePath()
	{
		return filepath;
	}
	public String getFileName()
	{
		return (filename!=null) ? filename : "(New Document)" ;
	}
	
	public void setFilePath( String newPath )
	{
		filepath = filename = newPath;
	}
	
	public boolean getModified()
	{
		return isModified;
	}
	public void setModified(boolean set)
	{
		if(isModified != set )
		{
			isModified = set;
			if( modifiedCallback != null ) modifiedCallback.callback();
		}
	}
	
	public void setModifiedCallback( Callback callback )
	{
		modifiedCallback = callback;
	}
	
	public Callback getModifiedCallback()
	{
		return modifiedCallback;
	}
	
	public int getLineHeight()
	{
		return super.getRowHeight();
	}
	
	
}
